<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
  <th:block th:include="include :: header('方案案例指定')" />
</head>
<body class="gray-bg">
<div class="container-div">
  <div class="row">
    <div class="col-sm-12">
      <form id="assign-project-form">
        <input type="hidden" id="planId" name="planId" th:value="${planId}">
      </form>
    </div>
    <div class="btn-group-sm" id="toolbar" role="group">
      <a class="btn btn-success" onclick="selectProject()" shiro:hasPermission="sewage:sewagePlan:add">
        <i class="fa fa-plus"></i> 添加案例
      </a>
      <a class="btn btn-danger btn-del disabled" onclick="cancelAssignProjectAll()" shiro:hasPermission="sewage:sewagePlan:remove">
        <i class="fa fa-remove"></i> 批量取消指定
      </a>
      <a class="btn btn-warning" onclick="closeItem()">
        <i class="fa fa-reply-all"></i> 关闭
      </a>
    </div>

    <div class="col-sm-12 select-table table-striped">
      <table id="bootstrap-table" data-mobile-responsive="true"></table>
    </div>
  </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
  var removeFlag = [[${@permission.hasPermi('sewage:sewagePlan:remove')}]];
  var sewageDatas = [[${@dict.getType('sewage_type')}]];
  var prefix = ctx + "sewage/sewagePlan";

  $(function() {
    var options = {
      url: prefix + "/projectList",
      queryParams: queryParams,
      showSearch: false,
      modalName: "案例",
      columns: [{
        checkbox: true
      },
        {
          field : 'projectId',
          title : '项目ID',
          visible: false
        },
        {
          field : 'projectName',
          title : '项目名称'
        },
        {
          field : 'sewageType',
          title : '污水类型',
          formatter: function(value, row, index) {
            return $.table.selectDictLabel(sewageDatas, value);
          }
        },
        {
          field : 'designIntake',
          title : '设计进水量(t/d)'
        },
        {
          field : 'actualIntake',
          title : '实际进水量(t/d)'
        },
        {
          title: '操作',
          align: 'center',
          formatter: function(value, row, index) {
            var actions = [];
            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="cancelAssignProject(\'' + row.projectId + '\')"><i class="fa fa-remove"></i>取消分配</a> ');
            return actions.join('');
          }
        }]
    };
    $.table.init(options);
  });

  function queryParams(params) {
    var search = $.table.queryParams(params);
    search.planId = $("#planId").val();
    return search;
  }

  function selectProject() {
    var url = prefix + '/selectProject/' + $("#planId").val();
    $.modal.open("选择案例", url);
  }

  function cancelAssignProjectAll() {
    var rows = $.table.selectFirstColumns();
    if (rows.length == 0) {
      $.modal.alertWarning("请至少选择一条记录");
      return;
    }
    $.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
      var data = { "planId": $("#planId").val(), "projectIds": rows.join() };
      $.operate.submit(prefix + "/projectCancelAll", "post", "json", data);
    });
  }

  function cancelAssignProject(projectId) {
    $.modal.confirm("确认要取消该解决方案案例吗？", function() {
      $.operate.post(prefix + "/projectCancel", { "planId": $("#planId").val(), "projectId": projectId });
    });
  }
</script>
</body>
</html>